/**
 * scala连接kafka
 * <dependency>
 * <groupId>org.apache.kafka</groupId>
 * <artifactId>kafka_2.11</artifactId>
 * <version>2.2.0</version>
 * </dependency>
 *
 *
 *
 * 可运行
 *
 */
package com.atguigu.day6


import java.util.Properties
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}

object ScalaToKafka {
  def main(args: Array[String]): Unit = {
    writeToKafka("hotitems")
  }
  def writeToKafka(topic: String):Unit={
    val pros = new Properties()

    pros.put("bootstrap.servers", "192.168.35.102:9092")
    pros.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
    pros.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")

    val producer = new KafkaProducer[String,String](pros)
    val bufferedSource = io.Source.fromFile("D:\\job\\idea\\idea2018_workspces\\flink\\src\\main\\resources\\UserBehavior.csv")
    for (line <- bufferedSource.getLines()){
      val record = new ProducerRecord[String,String](topic,line)
      producer.send(record)
    }
    producer.close()
  }

}
